﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECCIT.Data;
using System.Data;
using System.Data.SqlClient;

using ECCIT.Business.Model;
using OgilvyOne.UKNow.Model;

namespace OgilvyOne.UKNow.DAL
{
    public class HomeViewCountDAL
    {
        //修改数据访问量的记录
        public bool Update(int langID)
        {
            string sqlcmd = "";
            if (langID == 2052)
              sqlcmd = "update dbo.UKNOW_HOME_VIEW_COUNT set COL_CNHOME_VIEW_COUNT=COL_CNHOME_VIEW_COUNT+1,COL_CNHOME_DISP_COUNT=COL_CNHOME_DISP_COUNT+1 where COL_REC_ID=1";
            if (langID == 1033)
              sqlcmd = "update dbo.UKNOW_HOME_VIEW_COUNT set COL_ENHOME_VIEW_COUNT=COL_ENHOME_VIEW_COUNT+1,COL_ENHOME_DISP_COUNT=COL_ENHOME_DISP_COUNT+1 where COL_REC_ID=1";
            bool res = DBHelper.ExecuteNonQuery(sqlcmd)>0;
            return res;
        }
        //获得数据访问量的记录

        public int  GetModel()
        {
            int count = 0;
            string sqlcmd = "select * from dbo.UKNOW_HOME_VIEW_COUNT";
            DataSet ds = DBHelper.ExecuteDataSet(sqlcmd, null);
            if (ds.Tables[0].Rows.Count>0)
            {
                HomeViewCountModel model = new HomeViewCountModel();
                DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    model.Col_rec_id = Convert.ToInt32(dr["COL_REC_ID"]);
                    model.Col_cnhome_view_count = Convert.ToInt32(dr["COL_CNHOME_VIEW_COUNT"]);
                    model.Col_cnhome_disp_count = Convert.ToInt32(dr["COL_CNHOME_DISP_COUNT"]);
                    model.Col_enhome_view_count = Convert.ToInt32(dr["COL_ENHOME_VIEW_COUNT"]);
                    model.Col_enhome_disp_count = Convert.ToInt32(dr["COL_ENHOME_DISP_COUNT"]);
                }
                count = model.Col_cnhome_view_count + model.Col_enhome_view_count;
                return count;
            }
            else
            {
                return 0;
            }
        
        }
    }
}
